<?php
require "./common/function.php";

$a = $_REQUEST['a'];
//商品管理
if($a=='product'){
//    获取查询条件
    $productId=$_REQUEST['productId'];
    $cateId = $_REQUEST['category'];
    $name = $_REQUEST['productName'];
    $minPrice = $_REQUEST['minPrice'];
    $maxPrice = $_REQUEST['maxPrice'];

//    拼接查询条件
    $str = "";
    if(!empty($productId)){
        $str = " and a.id='$productId'";
    }
    if(!empty($cateId)){
        $str .= " and a.category='$cateId'";
    }
    if(!empty($name)){
        $str .= " and a.name='$name'";
    }
    if(!empty($minPrice) && !empty($maxPrice)){
        $str .= " and a.price between '$minPrice' and '$maxPrice' ";
    }
//    查询所有商品信息
    $sql="SELECT a.id,a.`name`, a.price,a.pnum, a.imgurl,a.description, a.`status`,b.category FROM t_product a LEFT JOIN t_category b ON a.category = b.id where 1=1 ";
    $sql .= $str;
    $result = getMySql($sql,"查询商品信息失败");
    if($result){
        if(mysqli_num_rows($result)){
           $products = mysqli_fetch_all($result,MYSQLI_ASSOC);
        }
    }

//    查询分类（栏目）信息
    $sql2 = "select * from t_category";
    $result2 = getMySql($sql2,"查询商品分类信息失败");
    if($result2){
        if(mysqli_num_rows($result2)){
            $category = mysqli_fetch_all($result2,MYSQLI_ASSOC);
        }
    }

    require "./html/product.html";
    exit;
}


require "./html/right.html";
exit;
